﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using SmallSoft.Language.Model.Interface;
using SmallSoft.Language.Model.Factory;

namespace SmallSoft.Language.Database
{
    public class BinaryDatabase
    {
        private String fileName;
        public BinaryDatabase()
        {

        }
        public List<IWordModel> GetData()
        {
            List<IWordModel> data = new List<IWordModel>();
            GenFileName();

            FileStream fs=new FileStream(fileName,FileMode.OpenOrCreate);

            StreamReader sr = new StreamReader(fs);
            String strData = sr.ReadToEnd();

            String[] result = strData.Split(new char[] { '/' });
            for (int i=0;i<result.Length/3;i++)
            {
                IWordModel wm = WordModelFactory.GetWordModel();
                wm.Word=result[3*i];
                wm.Speel=result[3*i+1];
                wm.WordMean=result[3*i+2];
                data.Add(wm);
            }

            return data;
        }
        private void GenFileName()
        {
            fileName = Environment.CurrentDirectory + "\\DictDatabase.txt";
        }
    }
}
